package com.uinnova.product.eam.mvc;

import com.alibaba.fastjson.JSON;
import com.binary.framework.web.RemoteResult;
import com.uinnova.product.eam.model.es.ArchFinalReviewExpertDetailConf;
import com.uinnova.product.eam.service.PreReviewFinalExpertConfService;
import com.uinnova.product.eam.vo.PreReviewFinalExpertSaveVO;
import oracle.jdbc.proxy.annotation.Pre;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/pre/final/expert/conf")
public class PreReviewFinalExpertConfController {
    @Autowired
    private PreReviewFinalExpertConfService preReviewFinalExpertConfService;

    @PostMapping("/save")
    public RemoteResult save(@RequestBody List<PreReviewFinalExpertSaveVO> preReviewFinalExpertSaveVOs) {
        Boolean result = preReviewFinalExpertConfService.save(preReviewFinalExpertSaveVOs);
        return new RemoteResult(result);
    }

    @PostMapping("/checkPre")
    public RemoteResult checkPre(@RequestBody List<PreReviewFinalExpertSaveVO> saveVOs) {
        preReviewFinalExpertConfService.checkPre(saveVOs);
        return new RemoteResult("success");
    }

    @GetMapping("/list")
    public RemoteResult list() {
        List<ArchFinalReviewExpertDetailConf> result = preReviewFinalExpertConfService.list();
        return new RemoteResult(result);
    }

    @GetMapping("/toFlowableList")
    public List<Map<String,String>> toFlowableList() {
        List<ArchFinalReviewExpertDetailConf> list = preReviewFinalExpertConfService.list();
        List<Map<String,String>> result = getMapResult(list);
        return result;
    }

    private List<Map<String, String>> getMapResult(List<ArchFinalReviewExpertDetailConf> list) {
        List<Map<String,String>> result = new ArrayList<>();
        for (ArchFinalReviewExpertDetailConf archFinalReviewExpertDetailConf : list) {
            Map<String,String> map = new HashMap<>();
            List<String> experts = archFinalReviewExpertDetailConf.getExperts();
            map.put("experts",String.join(",",experts));
            map.put("domainId",archFinalReviewExpertDetailConf.getId().toString());
            map.put("domainName",archFinalReviewExpertDetailConf.getDomain());
            result.add(map);
        }
        return result;
    }

}
